/**
 * Created with  SublimeText
 * @Author:      Lyle
 * @DateTime:    2017-03-09 14:59:49
 * @Description: 
 */

import * as API from '../../api'

const state = {
    siteNumState: JSON.parse(Unit.getSessionStorage("siteNumState")) || {},
    siteNavBottom: {
        browse: 'browse'
    }
}

const mutations = {

    saveFxiedOptionsData: function(state, data) {
        //console.log('mutations saveFxiedOptionsData', data);
        for (var item in data) {
            Unit.setLocalStorage("ms_" + item, JSON.stringify(data[item]));
        }
    },

    saveSiteNumState: function(state, data) {
        //console.log('mutations saveSiteNumState', data);
        state.siteNumState = data;
        Unit.setSessionStorage("siteNumState", JSON.stringify(state.siteNumState));
    },

    saveSiteNavBottom: function(state, data) {
        state.siteNavBottom = data;
    },

}

const actions = {

    requestFxiedOptionsData({ commit, state }, type) {
        let tthis = this;
        if (type || !Unit.getLocalStorage('ms_height')) {
            API.get_profile_options({
                data: {},
                success: (response) => {
                    commit('saveFxiedOptionsData', response.data);
                }
            })
        }
    },

    requestSiteNumStateData({ commit, state }, data) {
        API.status_bar_data({
            data: data,
            success: (response) => {
                commit('saveSiteNumState', response);
            }
        })
    },

    updateSiteNumStateData({ commit, state }, data) {
        commit('saveSiteNumState', data);
    },

    updateSiteNavBottom({ commit, state }, data) {
        commit('saveSiteNavBottom', data);
    },

}

const getters = {

}

export default {
    state,
    getters,
    actions,
    mutations
}
